package com.example.shoppingdemo.Center;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.shoppingdemo.R;

import java.util.List;

public class RightAdapter extends RecyclerView.Adapter<RightAdapter.RightHolder>{
    private Context context;

    private List<RightModel> rightData;
    private onRightItemClickListener listener;

    public void setListener(onRightItemClickListener listener) {
        this.listener = listener;
    }

    public RightAdapter(Context context)
    {
        this.context = context;
    }
    public void setRightData(List<RightModel> rightData)
    {
        this.rightData = rightData;
    }

    @NonNull

    @Override
    public RightHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RightHolder holder=new RightHolder(
                LayoutInflater.from(context).inflate(R.layout.center_list_item1,null));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null !=listener){
                    listener.onRightItemClick(holder.getAdapterPosition());
                }
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull  RightAdapter.RightHolder holder, int position) {
        holder.rightName.setText(rightData.get(position).getName());
        Glide.with(context).load(rightData.get(position).getIcon()).into( holder.imageView);
    }

    @Override
    public int getItemCount() {
        return null == rightData ? 0: rightData.size();
    }

    class RightHolder extends RecyclerView.ViewHolder
    {

        TextView rightName;
        ImageView imageView;

        public RightHolder(@NonNull View itemView)
        {
            super(itemView);
            rightName =
                    itemView.findViewById(R.id.list);
            imageView=itemView.findViewById(R.id.item);
        }
    }
   public interface onRightItemClickListener
    {

        void onRightItemClick(int position);
    }


}
